<template>
	<view :class="['page',{'iphoneX':isIphoneX}]">
		<template v-if="isLogin">

			<!-- 每日评价 -->
			<template v-if="type=='day'">
				<view class="body">
					<view class="hd-title">药剂评价</view>
					<view class="detail-wrap m-b2">
						<view class="item">
							<view class="title">药剂三证是否齐全：</view>
							<radio-group class="radio-group" @change="setEgal">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_egal==1"
										color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_egal==0"
										color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">药剂防治对象登记为红火蚁：</view>
							<radio-group class="radio-group" @change="setAnt">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_ant==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_ant==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">药剂在使用期限内：</view>
							<radio-group class="radio-group" @change="setValid">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_valid==1"
										color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_valid==0"
										color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">有药剂出入库登记管理：</view>
							<radio-group class="radio-group" @change="setRegister">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_register==1"
										color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_register==0"
										color="#f00" />
								</label>
							</radio-group>
						</view>
					</view>
					<!-- 图片上传 -->
					<view class="form-wrap m-b2">
						<view class="upload-pic-item">
							<view class="label">药剂照片</view>
							<view class="form-upload-pic">
								<template>
									<view class="img-item" v-for="(item,index) in params.files_1" :key="index">
										<image src="@/static/images/filter_bg.png" mode="widthFix">
											<!-- 占位 -->
										</image>
										<view class="img-wrap" @click="previewPic(index,1)">
											<image class="img" :src="item.url" mode="widthFix"></image>
										</view>
										<view class="del-icon" @click="delPic(index,1)">
											<view class="iconfont">&#xe74b;</view>
										</view>
									</view>
								</template>
								<view class="img-item add-btn" @click="uploadImage(1)">
									<image src="@/static/images/upload_pic.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
					</view>

					<view class="hd-title">作业评价</view>
					<view class="detail-wrap m-b2">
						<view class="item">
							<view class="title">工具配备.安全防护评级：</view>
							<radio-group class="radio-group" @change="setToolRank">
								<label class="check-item">
									<view class="text">优</view>
									<radio class="radio" value="1" :checked="params.work_is_standard==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">良</view>
									<radio class="radio" value="2" :checked="params.work_is_standard==2" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">差</view>
									<radio class="radio" value="3" :checked="params.work_is_standard==3" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">施药是否规范：</view>
							<radio-group class="radio-group" @change="setStandard">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.work_is_standard==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.work_is_standard==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">完整记录施药时间、施药剂量、防治面积：</view>
							<radio-group class="radio-group" @change="setRecord">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.work_is_record==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.work_is_record==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">上传防控现场照片：</view>
							<radio-group class="radio-group" @change="setUpload">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.photo_is_upload==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.photo_is_upload==0" color="#f00" />
								</label>
							</radio-group>
						</view>
					</view>
					<!-- 图片上传 -->
					<view class="form-wrap m-b2">
						<view class="upload-pic-item">
							<view class="label">作业照片</view>
							<view class="form-upload-pic">
								<template>
									<view class="img-item" v-for="(item,index) in params.files_2" :key="index">
										<image src="@/static/images/filter_bg.png" mode="widthFix">
											<!-- 占位 -->
										</image>
										<view class="img-wrap" @click="previewPic(index,2)">
											<image class="img" :src="item.url" mode="widthFix"></image>
										</view>
										<view class="del-icon" @click="delPic(index,2)">
											<view class="iconfont">&#xe74b;</view>
										</view>
									</view>
								</template>
								<view class="img-item add-btn" @click="uploadImage(2)">
									<image src="@/static/images/upload_pic.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
					</view>

					<view class="form-wrap m-b2">
						<view class="form-textarea-item">
							<view class="label a-t">监理意见</view>
							<view class="form-textarea">
								<textarea class="inp-textarea" v-model="params.content" placeholder="监理意见"
									maxlength="-1"></textarea>
							</view>
						</view>
					</view>

					<view class="hd-title">总体评价</view>
					<view class="detail-wrap m-b2">
						<view class="item">
							<view class="title">今日作业是否合规：</view>
							<radio-group class="radio-group" @change="setPass">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.work_is_pass==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.work_is_pass==0" color="#f00" />
								</label>
							</radio-group>
						</view>
					</view>
 
					
				</view>
				<!-- 底部 -->
				<view class="footer">
					<view class="fix-wrap bottom">
						<view class="form-lay-btn" @click="submitDay">提交评价</view>
					</view>
				</view>
			</template>

			<!-- 阶段评价 -->
			<template v-if="type=='stage'">
				<view class="body">
					<view class="hd-title">药剂评价</view>
					<view class="detail-wrap m-b2">
						<view class="item">
							<view class="title">药剂三证是否齐全：</view>
							<radio-group class="radio-group" @change="setEgal">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_egal==1"
										color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_egal==0"
										color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">药剂防治对象登记为红火蚁：</view>
							<radio-group class="radio-group" @change="setAnt">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_ant==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_ant==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">药剂在使用期限内：</view>
							<radio-group class="radio-group" @change="setValid">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_valid==1"
										color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_valid==0"
										color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">有药剂出入库登记管理：</view>
							<radio-group class="radio-group" @change="setRegister">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.pesticide_is_register==1"
										color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.pesticide_is_register==0"
										color="#f00" />
								</label>
							</radio-group>
						</view>
					</view>
					<!-- 图片上传 -->
					<view class="form-wrap m-b2">
						<view class="upload-pic-item">
							<view class="label">药剂照片</view>
							<view class="form-upload-pic">
								<template>
									<view class="img-item" v-for="(item,index) in params.files_1" :key="index">
										<image src="@/static/images/filter_bg.png" mode="widthFix">
											<!-- 占位 -->
										</image>
										<view class="img-wrap" @click="previewPic(index,1)">
											<image class="img" :src="item.url" mode="widthFix"></image>
										</view>
										<view class="del-icon" @click="delPic(index,1)">
											<view class="iconfont">&#xe74b;</view>
										</view>
									</view>
								</template>
								<view class="img-item add-btn" @click="uploadImage(1)">
									<image src="@/static/images/upload_pic.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
					</view>

					<view class="hd-title">作业评价</view>
					<view class="detail-wrap m-b2">
						<view class="item">
							<view class="title">防治工作在红火蚁监测完成后的7个工作日内开展：</view>
							<radio-group class="radio-group" @change="setInweek">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params_stage.work_is_inweek==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params_stage.work_is_inweek==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">施药范围覆盖合同规定的区域及面积：</view>
							<radio-group class="radio-group" @change="setInarea">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params_stage.work_is_inarea==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params_stage.work_is_inarea==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">该阶段全面施药在合同规定时间内完成：</view>
							<radio-group class="radio-group" @change="setOntime">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params_stage.work_is_ontime==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params_stage.work_is_ontime==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="detail-item">
							<view class="label a-t">施药开始日期：</view>
							<picker class="detail-picker" mode="date" @change="changeDate($event,'start')">
								<view class="picker">
									<input type="text" v-model="params_stage.begin_time" placeholder="选择施药开始日期" disabled class="select-data t-l">
									<view class="icon">
										<view class="iconfont f-s68">&#xeb8a;</view>
									</view>
								</view>
							</picker>
						</view>

						<view class="detail-item">
							<view class="label a-t">施药结束日期</view>
							<picker class="detail-picker" mode="date" @change="changeDate($event,'end')">
								<view class="picker">
									<input type="text" v-model="params_stage.end_time" placeholder="选择施药结束日期" disabled class="select-data t-l">
									<view class="icon">
										<view class="iconfont f-s68">&#xeb8a;</view>
									</view>
								</view>
							</picker>
						</view>
						<view class="detail-item">
							<view class="label">实际作业时间：</view>
							<view class="detail-input">
								<view class="content">
									<view class="val">{{day}}</view>
									<view class="link">天</view>
								</view>
							</view>
						</view>
						<view class="item">
							<view class="title">工具配备.安全防护评级：</view>
							<radio-group class="radio-group" @change="setToolRank">
								<label class="check-item">
									<view class="text">优</view>
									<radio class="radio" value="1" :checked="params.tool_rank==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">良</view>
									<radio class="radio" value="2" :checked="params.tool_rank==2" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">差</view>
									<radio class="radio" value="3" :checked="params.tool_rank==3" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">施工前对作业人员进行不少于1次的工作培训：</view>
							<radio-group class="radio-group" @change="setTrain">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params_stage.worker_is_train==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params_stage.worker_is_train==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">施药是否规范：</view>
							<radio-group class="radio-group">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.work_is_standard==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.work_is_standard==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">完整记录施药时间、施药剂量、防治面积：</view>
							<radio-group class="radio-group">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.work_is_record==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.work_is_record==0" color="#f00" />
								</label>
							</radio-group>
						</view>
						<view class="item">
							<view class="title">是否上传防控现场照片：</view>
							<radio-group class="radio-group">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.photo_is_upload==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.photo_is_upload==0" color="#f00" />
								</label>
							</radio-group>
						</view>
					</view>
					<!-- 图片上传 -->
					<view class="form-wrap m-b2">
						<view class="upload-pic-item">
							<view class="label">作业照片</view>
							<view class="form-upload-pic">
								<template>
									<view class="img-item" v-for="(item,index) in params.files_2" :key="index">
										<image src="@/static/images/filter_bg.png" mode="widthFix">
											<!-- 占位 -->
										</image>
										<view class="img-wrap" @click="previewPic(index,2)">
											<image class="img" :src="item.url" mode="widthFix"></image>
										</view>
										<view class="del-icon" @click="delPic(index,2)">
											<view class="iconfont">&#xe74b;</view>
										</view>
									</view>
								</template>
								<view class="img-item add-btn" @click="uploadImage(2)">
									<image src="@/static/images/upload_pic.png" mode="widthFix"></image>
								</view>
							</view>
						</view>
					</view>

					<view class="hd-title">防效评价</view>
					<view class="form-wrap m-b2">
						<view class="form-item">
							<view class="label" style="width: 280rpx;">防控前总评等级：</view>
							<picker class="form-picker" mode="selector" :range="level" @change="changeLevel($event,'before')">
								<view class="picker">
									<input type="text" v-model="params_stage.before_relevel" placeholder="选择防控前总评等级" disabled class="select-data t-l">
									<view class="icon">
										<view class="iconfont f-s68">&#xeb8a;</view>
									</view>
								</view>
							</picker>
						</view>
						<view class="form-item">
							<view class="label" style="width: 280rpx;">防控后总评等级：</view>
							<picker class="form-picker" mode="selector" :range="level" @change="changeLevel($event,'after')">
								<view class="picker">
									<input type="text" v-model="params_stage.after_relevel" placeholder="选择防控后总评等级" disabled class="select-data t-l">
									<view class="icon">
										<view class="iconfont f-s68">&#xeb8a;</view>
									</view>
								</view>
							</picker>
						</view>
						<view class="form-item">
							<view class="label">活蚁巢减退率：</view>
							<view class="form-input">
								<view class="content">
									<input type="digit" class="inp" v-model="params_stage.nest_decline_rate" placeholder="输入活蚁巢减退率" />
									<view class="link">%</view>
				 			</view>
							</view>
						</view>
						<view class="form-item">
							<view class="label">工蚁减退率：</view>
							<view class="form-input">
								<view class="content">
									<input type="digit" class="inp" v-model="params_stage.ant_decline_rate" placeholder="输入工蚁减退率" />
									<view class="link">%</view>
								</view>
					 	</view>
						</view>
					</view>

					<view class="form-wrap m-b2">
						<view class="form-textarea-item">
							<view class="label a-t">监理意见</view>
							<view class="form-textarea">
								<textarea class="inp-textarea" v-model="params.content" placeholder="监理意见"
									maxlength="-1"></textarea>
							</view>
						</view>
					</view>

					<view class="hd-title">总体评价</view>
					<view class="detail-wrap m-b2">
						<view class="item">
							<view class="title">达到项目阶段目标：</view>
							<radio-group class="radio-group">
								<label class="check-item">
									<view class="text">是</view>
									<radio class="radio" value="1" :checked="params.work_is_pass==1" color="#f00" />
								</label>
								<label class="check-item">
									<view class="text">否</view>
									<radio class="radio" value="0" :checked="params.work_is_pass==0" color="#f00" />
								</label>
							</radio-group>
						</view>
					</view> 
					
				</view>
				
				<!-- 底部 -->
				<view class="footer">
					<view class="fix-wrap bottom">
						<view class="form-lay-btn" @click="submitStage">提交评价</view>
					</view>
				</view>

			</template>


		</template>
	</view>
</template>

<script>
	import {
		dateFormat,
		uploadImage,
		previewImage,
		uploadToServe
	} from '@/common/util.js'
	export default {
		name: 'name',
		data() {
			return {
				isLogin: true,
				isIphoneX: getApp().globalData.isIphoneX,
				userInfo: uni.getStorageSync('userInfo'),
				isStop: true,
				type: '',
				level: [1, 2, 3, 4, 5],
				params: {
					pesticide_is_egal: '1',
					pesticide_is_ant: '1',
					pesticide_is_valid: 1,
					pesticide_is_register: 1,
					tool_rank: 1,
					work_is_standard: 1,
					work_is_record: 1,
					photo_is_upload: 1,
					work_is_pass: 1,
					content: '',	 
					type: 1,
					p_id: '',
					files: [],
					files_1: [], // 药剂照片
					files_2: [] // 作业照片
				},
				params_stage:{ 
					work_is_inweek: 1,
					work_is_inarea: 1,
					work_is_ontime: 1,
					worker_is_train: 1,
					begin_time: '',
					end_time: '',					
					before_relevel: '',
					after_relevel: '',
					nest_decline_rate: '',
					ant_decline_rate: '',
				}
			}


		},
		async onLoad(params) {
			this.type = params.type;
			this.params.p_id = params.pid;
			this.isLogin = await this.$loginState('check');

			if (this.type == 'day') {
				uni.setNavigationBarTitle({
					title: "每日评价"
				})
			} else if (this.type == 'stage') {
				uni.setNavigationBarTitle({
					title: "阶段评价"
				})
			}

			if (this.isLogin) {

			}
		},
		async onShow() { 

		},
		methods: {

			// 三证齐全
			setEgal: function(e) {
				this.params.pesticide_is_egal = e.detail.value;
			},


			// 防治对象登记
			setAnt: function(e) {
				this.params.pesticide_is_ant = e.detail.value;
			},

			// 使用期限
			setValid: function(e) {
				this.params.pesticide_is_valid = e.detail.value;
			},

			// 出入库登记
			setRegister: function(e) {
				this.params.pesticide_is_register = e.detail.value;
			},

			// 安全防护等级
			setToolRank: function(e) {
				this.params.tool_rank = e.detail.value;
			},

			// 施药是否规范
			setStandard: function(e) {
				this.params.work_is_standard = e.detail.value;
			},

			// 记录是否完整
			setRecord: function(e) {
				this.params.work_is_record = e.detail.value;
			},

			// 是否上传图片
			setUpload: function(e) {
				this.params.photo_is_upload = e.detail.value;
			},

			// 是否合规
			setPass: function(e) {
				this.params.work_is_pass = e.detail.value;
			},
			
			// 是否7个工作日开展
			setInweek: function(e) {
				this.params_stage.work_is_inweek = e.detail.value;
			},
			
			// 是否覆盖合同面积
			setInarea: function(e) {
				this.params_stage.work_is_inarea = e.detail.value;
			},
			
			// 是否合同时间完成
			setOntime: function(e) {
				this.params_stage.work_is_ontime = e.detail.value;
			},
			
			// 是否对作业人员进行培训
			setTrain: function(e) {
				this.params_stage.worker_is_train = e.detail.value;
			}, 



			// 上传图片
			uploadImage: function(type) {
				// 上传现场照片
				let _this = this;
				uploadImage({
					length: _this.params.files.length,
					maxSize: 1,
					success(res) {
						uploadToServe({
							url: '/yfk/upload-file',
							filePath: res.tempFilePaths[0],
							name: 'photo',
							formData: {
								'p_id': 0,
								'create_uid': _this.userInfo.id
							}
						}).then((up_res) => {
							if (up_res.ret == 0) {
								let params_data = {};
								params_data.file_name = up_res.data.file_name;
								params_data.file_path = up_res.data.file_path;
								params_data.file_type = up_res.data.file_type;
								params_data.status = up_res.data.status;
								params_data.type = up_res.data.type;
								params_data.url = res.tempFilePaths[0];
								if (type == 1) {
									_this.params.files_1 = _this.params.files_1.concat(params_data);
								} else if (type == 2) {
									_this.params.files_2 = _this.params.files_2.concat(params_data);
								}

							}
						})
					}
				})
			},

			// 预览图片
			previewPic: function(index, type) {
				let _this = this;
				let preview_data = [];
				if (type == 1) {
					this.params.files_1.forEach(item => {
						preview_data.push(item.url);
					})
				} else if (type == 2) {
					this.params.files_2.forEach(item => {
						preview_data.push(item.url);
					})
				}

				previewImage({
					data: preview_data,
					index: index
				})
			},

			// 删除图片
			delPic: function(index, type) {
				if (type == 1) {
					this.params.files_1.splice(index, 1);
				} else if (type == 2) {
					this.params.files_2.splice(index, 1);
				}
			},

			// 提交每日评价数据
			submitDay: async function() {
				let _this = this; 

				if (this.params.files_1.length == 0) {
					uni.showToast({
						icon: 'none',
						title: '请上传药剂照片',
						mask: true,
						duration: 1000
					})
					return
				};
				if (this.params.photo_is_upload == '1') {
					if (this.params.files_2.length == 0) {
						uni.showToast({
							icon: 'none',
							title: '请上传作业照片',
							mask: true,
							duration: 1000
						})
						return
					};
				};

				let files = this.params.files_1.concat(this.params.files_2);

				if (this.isStop) {
					this.isStop = false;
					let res = await this.$api.ycj_api.adddata({
						pesticide_is_egal: this.params.pesticide_is_egal,
						pesticide_is_ant: this.params.pesticide_is_ant,
						pesticide_is_valid: this.params.pesticide_is_valid,
						pesticide_is_register: this.params.pesticide_is_register,
						tool_rank: this.params.tool_rank,
						work_is_standard: this.params.work_is_standard,
						work_is_record: this.params.work_is_record,
						photo_is_upload: this.params.photo_is_upload,
						work_is_pass: this.params.work_is_pass,
						content: this.params.content,
						type: 1,
						p_id: this.params.p_id,
						create_uid: this.userInfo.id,
						files: JSON.stringify(files),
					});

					uni.showLoading({
						title: "数据提交中...",
						mask: true
					})


					if (res.data.ret == 0) {
						uni.hideLoading();
						_this.$store.commit('UPDATE_PJ_LIST', true); // 数据更新
						uni.showToast({
							icon: 'success',
							title: res.data.message,
							mask: true,
							duration: 1000,
							success() {
								setTimeout(() => {
									_this.isStop = true;
									uni.navigateBack({
										delta: 1
									})
								}, 300)
							}
						})
					} else {
						uni.hideLoading();
						uni.showToast({
							image: '../../static/images/error.png',
							title: res.data.message,
							mask: true,
							duration: 1000,
							success() {
								setTimeout(() => {
									_this.isStop = true;
								})
							}
						})
					}

				}
			},
			
			// 防控等级切换
			changeLevel:function(e,type){
				if(type=='before'){
					this.params_stage.before_relevel=this.level[e.detail.value];
				}else if(type=='after'){
					this.params_stage.after_relevel=this.level[e.detail.value];
				}
			},
			
			// 施药日期切换
			changeDate:function(e,type){
				let start_times='',
					end_times='';
				if(type=='start'){
					this.params_stage.begin_time=e.detail.value;
				}else if(type=='end'){					 
					start_times=(new Date(this.params_stage.begin_time)).getTime()/1000;
					end_times=(new Date(e.detail.value)).getTime()/1000;
					if(end_times<start_times){
						uni.showToast({
							icon: 'none',
							title: '结束日期必须大于等于开始日期',
							mask: true,
							duration: 1000
						})
						return
					}else{
						this.params_stage.end_time=e.detail.value;
					}
				}
			},
			 
			// 提交阶段评价数据
			submitStage: async function() {
				let _this = this;
			 
				if (this.params.files_1.length == 0) {
					uni.showToast({
						icon: 'none',
						title: '请上传药剂照片',
						mask: true,
						duration: 1000
					})
					return
				};
				if (this.params_stage.begin_time == '') {
					uni.showToast({
						icon: 'none',
						title: '请选择施药开始日期',
						mask: true,
						duration: 1000
					})
					return
				};
				if (this.params_stage.end_time == '') {
					uni.showToast({
						icon: 'none',
						title: '请选择施药结束日期',
						mask: true,
						duration: 1000
					})
					return
				};
				if (this.params.photo_is_upload == '1') {
					if (this.params.files_2.length == 0) {
						uni.showToast({
							icon: 'none',
							title: '请上传作业照片',
							mask: true,
							duration: 1000
						})
						return
					};
				};
				if (this.params_stage.before_relevel == '') {
					uni.showToast({
						icon: 'none',
						title: '请选择防控前总评等级',
						mask: true,
						duration: 1000
					})
					return
				};
				if (this.params_stage.after_relevel == '') {
					uni.showToast({
						icon: 'none',
						title: '请选择防控后总评等级',
						mask: true,
						duration: 1000
					})
					return
				};
				if (this.params_stage.ant_decline_rate == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入活蚁巢减退率',
						mask: true,
						duration: 1000
					})
					return
				};
				if (this.params_stage.nest_decline_rate == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入工蚁减退率',
						mask: true,
						duration: 1000
					})
					return
				};
			
				let files = this.params.files_1.concat(this.params.files_2);
			
				if (this.isStop) {
					this.isStop = false;
					let res = await this.$api.ycj_api.adddata({
						pesticide_is_egal: this.params.pesticide_is_egal,
						pesticide_is_ant: this.params.pesticide_is_ant,
						pesticide_is_valid: this.params.pesticide_is_valid,
						pesticide_is_register: this.params.pesticide_is_register,
						work_is_inweek: this.params_stage.work_is_inweek,
						work_is_inarea: this.params_stage.work_is_inarea,
						work_is_ontime: this.params_stage.work_is_ontime,
						begin_time:this.params_stage.begin_time,
						end_time: this.params_stage.end_time,
						tool_rank: this.params.tool_rank,
						worker_is_train: this.params_stage.worker_is_train,
						work_is_standard: this.params.work_is_standard,
						work_is_record: this.params.work_is_record,
						photo_is_upload: this.params.photo_is_upload,
						before_relevel: this.params_stage.before_relevel,
						after_relevel: this.params_stage.after_relevel,
						nest_decline_rate: this.params_stage.nest_decline_rate,
						ant_decline_rate: this.params_stage.ant_decline_rate,
						work_is_pass: this.params.work_is_pass,
						content: this.params.content,
						type: 2,
						p_id: this.params.p_id,
						create_uid: this.userInfo.id,
						files: JSON.stringify(files), 
					});
			
					uni.showLoading({
						title: "数据提交中...",
						mask: true
					})
			
			
					if (res.data.ret == 0) {
						uni.hideLoading();
						_this.$store.commit('UPDATE_PJ_LIST', true); // 数据更新
						uni.showToast({
							icon: 'success',
							title: res.data.message,
							mask: true,
							duration: 1000,
							success() {
								setTimeout(() => {
									_this.isStop = true;
									uni.navigateBack({
										delta: 1
									})
								}, 300)
							}
						})
					} else {
						uni.hideLoading();
						uni.showToast({
							image: '../../static/images/error.png',
							title: res.data.message,
							mask: true,
							duration: 1000,
							success() {
								setTimeout(() => {
									_this.isStop = true;
								})
							}
						})
					}
			
				}
			},



		},
		components: {},

		computed: {
			day(){
				let day_num='';
				let start_times=(new Date(this.params_stage.begin_time)).getTime()/1000;
				let end_times=(new Date(this.params_stage.end_time)).getTime()/1000;
				day_num=(end_times-start_times)/(24*60*60)+1;
				return this.params_stage.begin_time&&this.params_stage.end_time?day_num:'';
			}
		},
		watch: {

		}

	}
</script>

<style lang="less" scoped>
	.detail-wrap {
		overflow: hidden;

		.title {
			padding: 30rpx 30rpx 0;
			font-size: 30rpx;
		}
	}

	.radio-group {
		display: flex;
		border-bottom: 1rpx solid #eee;

		.check-item {
			border-bottom: 0 none;
		}
	}


	.hd-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}


	.btn {
		@h: 80rpx;
		width: 98%;
		margin: 10rpx auto;
		text-align: center;
		height: @h;
		line-height: @h;
		background: linear-gradient(#e96b5c, #ce3c2f);
		border-radius: 10rpx;
		color: #fff;
		font-size: 34rpx;
	}
</style>
